﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Freedom.Models.Interfaces;
using System.Configuration;
using Freedom.Models.Entities;
using MySql.Data.MySqlClient;

namespace Freedom.Models.Services
{
    /// <summary>
    /// 博客信息服务
    /// autor: Penn Yao
    /// </summary>
    public class BlogInfoService : IBlogInfoService
    {
        public static string strConnectionString = ConfigurationManager.ConnectionStrings["db_BlogConnectionString"].ConnectionString;

        public BlogInfoService()
        {

        }

        /// <summary>
        /// 获取所有对象
        /// </summary>
        /// <param name="nCount">数量</param>
        /// <returns></returns>
        List<BlogInfo> IBlogInfoService.getAllInfo(int nCount)
        {
            List<BlogInfo> list = new List<BlogInfo>();
            string sql = "select gid,title,stitle,content,from_unixtime(date) as date from tb_blog order by gid desc limit 0, " + nCount;
            MySqlParameter[] parameters = {
	                    
				};
            using (var dr = MySqlHelper.ExecuteReader(strConnectionString, sql, parameters))
            {
                while (dr.Read())
                {
                    list.Add(new BlogInfo()
                    {
                        gid = int.Parse(dr["gid"].ToString()),
                        title = dr["title"].ToString(),
                        stitle = dr["stitle"].ToString(),
                        content = dr["content"].ToString(),
                        date = dr["date"].ToString()
                    });
                }
            }
            return list;
        }
    }
}